package com.bw.car.view


import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.constants.RoutePath
import com.bw.car.R
import com.bw.car.databinding.ActivityCarPayBinding
import com.bw.car.entity.PayParam
import com.bw.car.net.CarViewModel
import com.bw.common.view.BaseMvvmActivity
import java.text.SimpleDateFormat


/**
 * 智慧园区-02-停车缴费V1.1
 * 停车缴费
 * 刘晓贺
 * 20250510
 */
@Route(path = RoutePath.PATH_CAR_PAY)
class CarPayActivity : BaseMvvmActivity<ActivityCarPayBinding, CarViewModel>() {


    @Autowired
    lateinit var carCode: String
    override fun onCreate(savedInstanceState: Bundle?) {
        ARouter.getInstance().inject(this)
        super.onCreate(savedInstanceState)
    }

    private val format: SimpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")

    override fun initView() {
        binding.carCode.text = this.carCode

        binding.pay.setOnClickListener {
            vm.pay( PayParam(
                entryTime = format.format(System.currentTimeMillis()),
                exitTime = format.format(System.currentTimeMillis()+1000*60*60*6),
                id = 0,
                parkingDuration = 60,
                parkingSpaceNumber = "A10",
                paymentAmount = 3500,
                paymentMethod = 1,
                paymentTime = format.format(System.currentTimeMillis()),
                paymentType = 1,
                plateNumber = binding.carCode.text.toString(),
                reservationId = 0
            ))
        }
    }

    override fun initData() {
        vm.paySuccess.observe(this){
            ToastUtils.showShort("支付成功")
            finish()
        }
    }

}